//
//  StatusTopView.swift
//  Tanenbaum_blog
//
//  Created by Tanenbaum on 15/8/2.
//  Copyright © 2015年 GZJ. All rights reserved.
//

import UIKit
import SDWebImage


class StatusTopView: UIView {

   
    var status: Status? {
        didSet {
         
            if let url = status?.user?.imageURL {
                
                iconView .sd_setImageWithURL(url)
            }
        
            name.text = status?.user?.name ?? ""
            memberIconView.image = status?.user?.memberImage
            vipIconView.image = status?.user?.vipImage
            
            time.text = "刚刚"
            source.text = "iPhone6"
            
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.whiteColor()
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
       
        super.init(coder: aDecoder)
    }
    
    private func prepareUI() {
        
        //设置间隔视图
        let sepView = UIView()
        sepView.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        addSubview(sepView)
        sepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        
        //添加视图
        addSubview(iconView)
        addSubview(name)
        addSubview(time)
        addSubview(source)
        addSubview(memberIconView)
        addSubview(vipIconView)
        
        //设置布局
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: sepView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        name.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: satusCellControlMargin, y: 0))
        time.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: satusCellControlMargin, y: 0))
        source.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: time, size: nil, offset: CGPoint(x: satusCellControlMargin, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: name, size: nil, offset: CGPoint(x: satusCellControlMargin, y: 0))
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: satusCellControlMargin, y: satusCellControlMargin))
    }
    
    //MARK--懒加载控件
    //1、头像
    private lazy var iconView: UIImageView = UIImageView()
    //2、姓名
    private lazy var name: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    //3、时间
    private lazy var time: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    //4、来源
    private lazy var source: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    //5、会员图标
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //6、vip图标
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
}
